package com.wangrui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wangrui.dto.MajorSchool;
import com.wangrui.utils.Page;
import com.wangrui.pojo.Major;
import com.wangrui.mapper.MajorMapper;
import com.wangrui.service.MajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王锐
 * @since 2020-07-10
 */
@Service
public class MajorServiceImpl extends ServiceImpl<MajorMapper, Major> implements MajorService {
    @Autowired
    private MajorMapper majorMapper;
    @Override
    public Map<String, Object> AllMajors(Page<MajorSchool> page1) {
        majorMapper.getMajorSchool(page1);
        Map<String, Object> map = new HashMap<>();
        map.put("rows", majorMapper.getMajorSchool(page1));
        map.put("total", majorMapper.selectCount(null));
        return map;
    }

    @Override
    public int majorSave(Major major) {
        return majorMapper.insert(major);
    }

    @Override
    public int majorUpdate(Major major) {
        return majorMapper.updateById(major);
    }

    @Override
    public int majorDelete(int ids) {
        return majorMapper.deleteById(ids);
    }

    @Override
    public List<Major> queryMajorsJson() {
        QueryWrapper<Major> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","name");
        return majorMapper.selectList(queryWrapper);
    }

}
